
import 'package:flutter/material.dart';
import 'package:xvideos/assets_tool/app_colors.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

import '../../../../tools_base/event_bus/event_bus_util.dart';
import '../../../../tools_base/indicator/custom_tab_indicator.dart';
import '../community_tag_page.dart';


class UserCenterTabbar extends StatefulWidget {
  final TabController controller;
  final TabController? subTabCtr;
  final List<String>? tabs;

  UserCenterTabbar(this.controller, {this.subTabCtr, super.key, this.tabs});

  @override
  State<UserCenterTabbar> createState() => _UserCenterTabbarState();
}

class _UserCenterTabbarState extends State<UserCenterTabbar> with TickerProviderStateMixin {
  late TabController mainTabCtr;

  late List<String> tabs;
  final subTabs = ['最热', '最新'];

  @override
  void initState() {
    tabs = widget.tabs ?? ['抖音', '图文', '影视'];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (widget.subTabCtr != null) {
      return Row(
        children: [
          16.sizeBoxW,
          Spacer(),
          Container(
            height: 20,
            width: 72,
            margin: EdgeInsets.only(right: 16),
            decoration: BoxDecoration(color: Colors.white.withOpacity(0.05), borderRadius: BorderRadius.circular(20)),
            child: TabBar(
              tabAlignment: TabAlignment.start,
              controller: widget.subTabCtr,
              tabs: List.generate(
                subTabs.length,
                    (index) => Tab(
                  child: Container(
                    padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
                    child: Text(
                      subTabs[index],
                      maxLines: 1,
                    ),
                  ),
                ),
              ),
              indicatorWeight: 0,
              isScrollable: true,
              labelStyle: const TextStyle(
                fontSize: 10,
                color: Colors.white,
                fontWeight: FontWeight.w400,
              ),
              indicatorSize: TabBarIndicatorSize.tab,
              labelPadding: EdgeInsets.zero,
              unselectedLabelStyle: TextStyle(
                fontSize: 10,
                fontWeight: FontWeight.w400,
                color: Colors.white,
              ),
              onTap: (index) {
                eventBus.emit(UserCenterSortTypeEvent(index));
              },
              indicator: BoxDecoration(
                  color: Color(0x33F68216),
                  border: Border.all(color: AppColors.primaryHighColor, width: 1),
                  borderRadius: BorderRadius.circular(20)),
            ),
          )
        ],
      );
    } else {
      return TabBar(
        padding: EdgeInsets.only(top: 8, bottom: 3),
        controller: widget.controller,
        tabs: List.generate(
          tabs.length,
              (index) => Text(tabs[index]),
        ),
        labelPadding: EdgeInsets.only(bottom: 3, left: 14, right: 14),
        indicator: CustomIndicator(width: 13, height: 3, color: AppColors.primaryHighColor),
        isScrollable: true,
        tabAlignment: TabAlignment.center,
        labelColor: const Color(0xffffffff),
        labelStyle: TextStyle(
          fontSize: 15,
          fontWeight: FontWeight.w500,
        ),
        unselectedLabelColor: const Color(0x99ffffff),
        unselectedLabelStyle: TextStyle(
          fontSize: 15,
          fontWeight: FontWeight.w400,
        ),
      );
    }
  }
}

